







//
//  EquipTypeSwitchViewController.m
//  nncloud
//
//  Created by macfeel on 2019/6/14.
//  Copyright © 2019 macfai. All rights reserved.
//

#import "EquipTypeSwitchViewController.h"
#import "UIColor+Hex.h"
#import "ZNavigationViewController.h"
#import "NRootViewController.h"
#import "NHomeViewController.h"
#import "NBusinessServiceViewController.h"
#import "NMineViewController.h"
#import "NGovDeskViewController.h"
#import "NGovHomeViewController.h"
#import "NZhichengPingshenVC.h"
#import "CamelViewController.h"
#import "MsgViewController.h"
#import "AddressBookViewController.h"
#import "WorkFlowViewController.h"
#import "UserCenterViewController.h"

@interface EquipTypeSwitchViewController ()
@property (nonatomic,strong)NHomeViewController *home;
@property (nonatomic,strong)NBusinessServiceViewController *serve;
@property (nonatomic,strong)NMineViewController *mine;
@property (nonatomic,strong)NGovHomeViewController *govHome;
@property (nonatomic,strong)NGovDeskViewController *govDesk;

@property (nonatomic,strong)CamelViewController *camel;
@property (nonatomic,strong)MsgViewController *msg;
@property (nonatomic,strong)AddressBookViewController *addressBook;
@property (nonatomic,strong)WorkFlowViewController *workflow;
@property (nonatomic,strong)UserCenterViewController *userCenter;
@end

@implementation EquipTypeSwitchViewController

-(NHomeViewController *)home{
    if (!_home) {
        _home = [[NHomeViewController alloc] init];
        _home.title = @"首页";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"首页" image:[UIImage imageNamed:@"home"] selectedImage:[UIImage imageNamed:@"home_s"]];
        _home.tabBarItem=s_bar;
    }
    return _home;
}

-(NBusinessServiceViewController *)serve{
    
    if (!_serve) {
        
        _serve = [[NBusinessServiceViewController alloc] init];
        _serve.title=@"服务";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"服务" image:[UIImage imageNamed:@"serve"] selectedImage:[UIImage imageNamed:@"serve_s"]];
        _serve.tabBarItem=s_bar;
    }
    return _serve;
}

-(NMineViewController *)mine{
    if (!_mine) {
        _mine = [[NMineViewController alloc] init];
        _mine.title = @"我的";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"我的" image:[UIImage imageNamed:@"me"] selectedImage:[UIImage imageNamed:@"me_s"]];
        _mine.tabBarItem=s_bar;
    }
    return _mine;
}

-(NGovDeskViewController *)govDesk{
    
    if (!_govDesk) {
        _govDesk = [[NGovDeskViewController alloc] init];
        _govDesk.title=@"驼峰工区";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@"desk"] selectedImage:[UIImage imageNamed:@"desk_s"]];
        _govDesk.tabBarItem=s_bar;
    }
    
    return _govDesk;
}

-(NGovHomeViewController *)govHome{
    if (!_govHome) {
        _govHome = [[NGovHomeViewController alloc] init];
        _govHome.title=@"政府主页";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"政府主页" image:[UIImage imageNamed:@"home"] selectedImage:[UIImage imageNamed:@"home_s"]];
        _govHome.tabBarItem=s_bar;
    }
    return _govHome;
}

-(CamelViewController *)camel{
    if (!_camel) {
        _camel = [[CamelViewController alloc] init];
        _camel.title=@"驼峰工区";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
        _camel.tabBarItem=s_bar;
    }
    return _camel;
}

-(MsgViewController *)msg{
    if (!_msg) {
        _msg = [[MsgViewController alloc] init];
        _msg.title=@"驼峰工区";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
        _msg.tabBarItem=s_bar;
    }
    return _msg;
}

-(AddressBookViewController *)addressBook{
    if (!_addressBook) {
        _addressBook = [[AddressBookViewController alloc] init];
        _addressBook.title=@"驼峰工区";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
        _addressBook.tabBarItem=s_bar;
    }
    return _addressBook;
}


-(WorkFlowViewController *)workflow{
    if (!_workflow) {
        _workflow = [[WorkFlowViewController alloc] init];
        _workflow.title=@"驼峰工区";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
        _workflow.tabBarItem=s_bar;
    }
    return _workflow;
}

- (UserCenterViewController *)userCenter{
    if (!_userCenter) {
        _userCenter = [[UserCenterViewController alloc] init];
        _userCenter.title=@"驼峰工区";
        UITabBarItem *s_bar=[[UITabBarItem alloc]initWithTitle:@"驼峰工区" image:[UIImage imageNamed:@""] selectedImage:[UIImage imageNamed:@""]];
        _userCenter.tabBarItem=s_bar;
    }
    return _userCenter;
}


- (void)viewDidLoad {
    
    [super viewDidLoad];
//    self.view.backgroundColor = kMagentaColor;
    NSDictionary *userInfo = [[NSUserDefaults standardUserDefaults]objectForKey:kSaveUserInfoKey];
    YYLog(@"****%@",userInfo[@"userInfoType"]);
    
    if (userInfo) {
        
        NUserModel *model = [NUserModel shareInstance];
        [model setValuesForKeysWithDictionary:userInfo];
        YYLog(@"%@,%@",model.userInfoNickname,[NUserModel shareInstance].userInfoId);
        //自动登录
        [NUserModel shareInstance].isLogin = YES;

    }
    
//    [self configTabBarVC];
    
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    ///这个放在didload中就会有问题
    [self configTabBarVC];
}


//-(void)viewWillDisappear:(BOOL)animated{
//    
//    [super viewWillDisappear:animated];
//    ///将bool 值恢复初始状态
//   
//}

-(void)configTabBarVC{
    
    
    NSArray * titleArray;
    NSArray * unSelectImageArray;
    NSArray * selectImageArray;
    
    ZNavigationViewController * nav0 = [[ZNavigationViewController alloc] initWithRootViewController:self.home];
    ZNavigationViewController * nav1 = [[ZNavigationViewController alloc] initWithRootViewController:self.serve];
    ZNavigationViewController * nav2 = [[ZNavigationViewController alloc] initWithRootViewController:self.mine];
    ZNavigationViewController * nav3 = [[ZNavigationViewController alloc] initWithRootViewController:self.camel];
    
    self.viewControllers = @[nav0,nav1,nav2,nav3];
    
    titleArray = @[@"继电器",
                   @"转辙机",
                   @"综合器材",
                   @"驼峰器材"];
    
    unSelectImageArray = @[@"home",
                           @"desk",
                           @"serve",
                           
                           @"desk",
                           ];
    selectImageArray = @[@"home_s",
                         @"desk_s",
                         @"serve_s",
                        
                         @"desk_s",];
    
    
    for (int i=0; i < unSelectImageArray.count; i++) {
        
        NSString * titel = titleArray[i];
        
        UIImage * normal_image = [UIImage imageNamed:unSelectImageArray[i]];
        normal_image = [normal_image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        UIImage * selected_image = [UIImage imageNamed:selectImageArray[i]];
        //取消系统对于选中 item 的渲染
        selected_image = [selected_image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        //获取每一个 item
        UITabBarItem *item=[self.tabBar.items objectAtIndex:i];
        
        item = [item initWithTitle:titel
                             image:normal_image
                     selectedImage:selected_image];
        
        //item.imageInsets = UIEdgeInsetsMake(5, 5, -5, -5);
        [item setTitlePositionAdjustment:UIOffsetMake(0, -2)];
    
        
    }
    
    //设置 tabbar 字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:kDarkGrayColor, NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateNormal];
    //字颜色变化
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:kSystemtBlue, NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateSelected];
    
    
    NSNumber *equipType = [NUserModel shareInstance].scanEquipType;
    YYLog(@"%@",equipType);
//    NSNumber *equipType =
    if ([equipType isEqualToNumber:@(1)]) {
        self.selectedIndex = 0;
    }else if([equipType isEqualToNumber:@(2)]){
        self.selectedIndex = 1;
    }else if([equipType isEqualToNumber:@(3)]){
        self.selectedIndex = 2;
    }else{
        self.selectedIndex = 3;
    }
    
}

@end
